//
//  BBRegisterRequest.m
//  BabyThermometer
//
//  Created by CaiLei on 10/20/14.
//  Copyright (c) 2014 baohu. All rights reserved.
//

#import "BBRegisterRequest.h"
@implementation BBRegisterRequestItem
@end

@implementation BBRegisterRequest {
    void(^_completeBlock)(BBRegisterRequestItem *retItem, NSError *error);
}

- (id)init {
    self = [super init];
    if (self) {
        self.urlHead = @"http://123.57.38.59:7001/baohu/servlet/register";
        self.os = @"1";
    }
    return self;
}

- (void)startRequestWithBlock:(void(^)(BBRegisterRequestItem *retItem, NSError *error))aBlock {
    _completeBlock = aBlock;
    [self startRequest];
}

- (void)dealWithResponseJson:(NSString *)aJson andError:(NSError *)aError {
    if (aError) {
        _completeBlock(nil, aError);
        return;
    }
    
    BBRegisterRequestItem *item = [[BBRegisterRequestItem alloc] initWithString:aJson error:&aError];
    if (aError) {
        _completeBlock(nil, aError);
        return;
    }
    
    if (item.code.intValue == 1001) {
        aError = [NSError errorWithDomain:@"注册" code:1001 userInfo:@{@"msg": @"账号已被注册"}];
        _completeBlock(item, aError);
        return;
    }
    _completeBlock(item, nil);
}

@end
